package com.ptszyxx.popose.module.main.mine.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.ItemMineTaskBinding;
import com.ptszyxx.popose.module.main.mine.vm.MineTaskVM;
import com.ysg.http.data.entity.mine.TaskEntity;

public class MineTaskAdapter extends BaseQuickAdapter<TaskEntity, BaseDataBindingHolder<ItemMineTaskBinding>> {

    private MineTaskVM viewModel;

    public MineTaskAdapter(MineTaskVM viewModel) {
        super(R.layout.item_mine_task);
        this.viewModel = viewModel;
    }

    @Override
    protected void convert(BaseDataBindingHolder<ItemMineTaskBinding> holder, TaskEntity item) {
        ItemMineTaskBinding binding = holder.getDataBinding();
        if (binding != null) {
            binding.setEntity(item);
            binding.setViewModel(viewModel);
            binding.executePendingBindings();

//            binding.tvDiamond.setText(getContext().getResources().getString(R.string.diamond) +"x"+ item.getDiamonds());
//            binding.tvDesc.setText(item.getTaskDesc());
//            YImageUtil.show(binding.ivIcon, item.getPic());
//            binding.tvTitle.setText(item.getTaskname());

            if (item.isComplete()) {
                binding.tvComplete.setText(getContext().getResources().getString(R.string.completed));
                binding.tvComplete.setTextColor(getContext().getResources().getColor(com.ysg.R.color.complete));
                binding.tvComplete.setBackground(getContext().getResources().getDrawable(R.drawable.shape_complete));
            } else {
                binding.tvComplete.setText(getContext().getResources().getString(R.string.uncompleted));
                binding.tvComplete.setTextColor(getContext().getResources().getColor(com.ysg.R.color.no_complete));
                binding.tvComplete.setBackground(getContext().getResources().getDrawable(R.drawable.shape_no_complete));
            }

            binding.tvComplete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (item.isComplete()){
                        return;
                    }
                    viewModel.onCompleteClick(item);
                }
            });

        }
    }








}
